package com.runchinaup.runchilibrary.modes.activity;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.runchinaup.runchilibrary.utils.ViewUtil;

/**
 * Created by liber on 2018/1/19.
 */

public abstract class RootActivity extends UtilActivity {


    protected BluetoothManager bluetoothManager;
    protected BluetoothAdapter bluetoothAdapter;
    static final int REQUEST_BT = 111;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(loadLayout());
        ActivityCollectorUtil.addActivity(this);
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        bluetoothManager = (BluetoothManager) getApplicationContext().getSystemService(BLUETOOTH_SERVICE);
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        loadLayout();
        initView();
        blueisOpen();
        ViewUtil.load(this);
    }

    private void blueisOpen() {
        if (!bluetoothAdapter.isEnabled()) {
            Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(intent, REQUEST_BT);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_BT) {

        }
    }

    public abstract int loadLayout();

    public abstract void initView();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollectorUtil.removeActivity(this);
    }
}
